﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Controls = Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Shapes = Windows.UI.Xaml.Shapes;
using Windows.Devices.Input;
using Windows.Foundation;
using BoolanSlide;
using Configuration;
using Windows.UI.Xaml.Controls;
using BoolanSlide.RedoUndo;


namespace BoolanElement
{
    public class BooEllipse:BooTextShapesBase
    {
        Shapes.Ellipse ellipse;
        public Shapes.Ellipse Ellipse 
        {
            get
            {
                return ellipse;
            }
            set
            {
                ellipse = value;
            }
        }

        BooEllipseElement ellipseElement;
        public BooEllipseElement EllipseElement
        {
            get {   return ellipseElement; }
        }

        public override BooElement Element
        {
            set { ellipseElement = (BooEllipseElement)value; }
            get { return ellipseElement; }
        }

        public override BooTextShapesBaseElement TextShapesBaseElement
        {
            get { return ellipseElement; }
        }

        public override Shapes.Shape Shape
        {
            get { return ellipse; }
        }

        public BooEllipse(BooEllipseElement element, SaveForRedoUndo saveForRedoUndo)
            : base(element)
        {
            this.ellipseElement = element;
            InitOriginal();
            Focus.InitFocusEvent(this);
            base.saveForRedoUndo = saveForRedoUndo;
        }

        public BooEllipse(BooEllipseElement element)
            : base(element)
        {
            this.ellipseElement = element;
            InitOriginalForThumbNails();
        }

        public override void InitShape()
        {
            ellipse = new Shapes.Ellipse();
         
            ellipse.Height = EllipseElement.ShapeHeight;
            ellipse.Width = EllipseElement.ShapeWidth;
        }    

        public override void ReSizeUI(double x, double y)
        {
            if (EllipseElement.ElementTransform.Width + x < 50 || EllipseElement.ElementTransform.Height+y<50)
            {
                return;
            }

            EllipseElement.ElementTransform.Width = EllipseElement.ElementTransform.Width + x;
            EllipseElement.ElementTransform.Height = EllipseElement.ElementTransform.Height + y;

            ellipseElement.PropertyChanged("Shape");
        }

        public override void ReMargin(double x, double y)
        {
            this.Element.ElementTransform.Translate.X += x;
            this.Element.ElementTransform.Translate.Y += y;    
        }

       

        protected override void BooUIBase_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
        {
            base.BooUIBase_ManipulationCompleted(sender, e);
            RedoUndoHelper.SaveStatus(this);
        }

        public override void ApplySize()
        {
            EllipseElement.ShapeWidth = EllipseElement.ElementTransform.Width;
            EllipseElement.ShapeHeight = EllipseElement.ElementTransform.Height;
            ellipse.Width = EllipseElement.ElementTransform.Width;
            ellipse.Height = EllipseElement.ElementTransform.Height;

            FullGrid.Width = EllipseElement.ElementTransform.Width;
            FullGrid.Height = EllipseElement.ElementTransform.Height;

            CenterStack.Width = EllipseElement.ElementTransform.Width;

            this.TextBox.Width = EllipseElement.ElementTransform.Width;
            EllipseElement.TextWidth = EllipseElement.ElementTransform.Width;


            Focus.FocusElls.ScopeRectangle.Width = EllipseElement.ElementTransform.Width;
            Focus.FocusElls.ScopeRectangle.Height = EllipseElement.ElementTransform.Height;
            Focus.SetFocuseEllipseMargin(EllipseElement.ElementTransform.Width, EllipseElement.ElementTransform.Height);

        }
    }
}
